home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Ghost 1.0 / source / Ghost ƒ / Ghost code / ghost setup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.9 KB  |  207 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        ghost setup.c
  4.  
  5. Purpose:    This module handles initial game setup -- choosing random
  6.             computer players, getting human player information, and
  7.             mixing up the order of all the players.
  8.  
  9.  
  10. Ghost -=- a classic word-building challenge
  11. Copyright (C) 1993 Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "ghost globals.h"
  31. #include "ghost setup.h"
  32. #include "msg graphics.h"
  33. #include "msg dialogs.h"
  34. #include "msg error.h"
  35. #include "msg prefs.h"
  36.  
  37. void MakeComputerPlayers(void)
  38. {
  39.     int            i,j;
  40.     
  41.     if (gNumComputerPlayers)
  42.     {
  43.         for (i=0; i<gNumComputerPlayers; i++)
  44.         {
  45.             gComputerIconIndex[i]=24;
  46.             while (gComputerIconIndex[i]==24)
  47.             {
  48.                 gComputerIconIndex[i]=(Random()%13)+12;
  49.                 j=0;
  50.                 while (j<i)
  51.                 {
  52.                     if (gComputerIconIndex[j++]==gComputerIconIndex[i])
  53.                     {
  54.                         gComputerIconIndex[i]=24;
  55.                         j=i;
  56.                     }
  57.                 }
  58.                 j=0;
  59.                 while (j<gNumHumanPlayers)
  60.                 {
  61.                     if (gComputerIconIndex[i]==gHumanIconIndex[j++])
  62.                     {
  63.                         gComputerIconIndex[i]=24;
  64.                         j=gNumHumanPlayers;
  65.                     }
  66.                 }
  67.             }
  68.             gComputerPlayerScore[i]=0;
  69.         }
  70.     }
  71. }
  72.  
  73. Boolean GetHumanPlayers(void)
  74. {
  75.     int            i;
  76.     DialogPtr    theDlog;
  77.     DialogPtr    iconDlog;
  78.     int            itemSelected;
  79.     int            iconSelected;
  80.     int            newleft;
  81.     int            newtop;
  82.     int            dlogID;
  83.     Boolean        done;
  84.     Boolean        play;
  85.     int            itemtype;
  86.     Handle        item;
  87.     Rect        box;
  88.     Str255        tempStr;
  89.  
  90.     gNumHumanPlayers=0;
  91.  
  92.     done=FALSE;
  93.     while (!done)
  94.     {
  95.         PositionDialog('DLOG', addPlayerDialog);
  96.         theDlog = GetNewDialog(addPlayerDialog, 0L, (WindowPtr)-1L);
  97.         
  98.         tempStr[0]=0x0f;
  99.         tempStr[1]='P';    tempStr[2]='l';    tempStr[3]='a';    tempStr[4]='y';
  100.         tempStr[5]='e';    tempStr[6]='r';    tempStr[7]=tempStr[10]=' ';
  101.         tempStr[8]='#';
  102.         tempStr[9]=(char)(49+(gNumHumanPlayers%0xff));
  103.  
  104.         tempStr[11]='s';    tempStr[12]='e';    tempStr[13]='t';
  105.         tempStr[14]='u';    tempStr[15]='p';        
  106.         
  107.         SetWTitle(theDlog, tempStr);
  108.     
  109.         GetDItem(theDlog, 5, &itemtype, &item, &box);
  110.     
  111.         if (gHumanName[gNumHumanPlayers]!=0L)
  112.         {
  113.             for (i=((char*)(*(gHumanName[gNumHumanPlayers])))[0]; i>=0; i--)
  114.                 tempStr[i]=((char*)(*(gHumanName[gNumHumanPlayers])))[i];
  115.             SetIText(item, tempStr);
  116.         }
  117.         else
  118.             SetIText(item, gMyName);
  119.         SelIText(theDlog, 5, 0, 32767);
  120.         ShowWindow(theDlog);
  121.         itemSelected=0;
  122.         while ((itemSelected!=1) && (itemSelected!=2) && (itemSelected!=3))
  123.         {
  124.             ModalDialog(0L, &itemSelected);
  125.         }
  126.         GetIText(item, tempStr);
  127.         HideWindow(theDlog);
  128.         DisposeDialog(theDlog);
  129.         
  130.         if (itemSelected==1) /* accept, choose icon */
  131.         {
  132.             if (tempStr[0]!=0x00)
  133.             {
  134.                 PositionDialog('DLOG', chooseIconDialog);
  135.                 iconDlog=GetNewDialog(chooseIconDialog, 0L, (WindowPtr)-1L);
  136.                 
  137.                 if (gHumanName[gNumHumanPlayers]!=0L)
  138.                     DisposeHandle(gHumanName[gNumHumanPlayers]);
  139.                 gHumanName[gNumHumanPlayers]=NewString(tempStr);
  140.                 SetWTitle(iconDlog, tempStr);
  141.                 ShowWindow(iconDlog);
  142.                 iconSelected=0;
  143.                 while ((iconSelected<1) || (iconSelected>26))
  144.                     ModalDialog(0L, &iconSelected);
  145.                 
  146.                 if (iconSelected==1) /* random */
  147.                 {
  148.                     gHumanIconIndex[gNumHumanPlayers]=24;
  149.                     while (gHumanIconIndex[gNumHumanPlayers]==24)
  150.                     {
  151.                         gHumanIconIndex[gNumHumanPlayers]=(Random()%13)+12;
  152.                         i=0;
  153.                         while (i<gNumHumanPlayers)
  154.                         {
  155.                             if (gHumanIconIndex[gNumHumanPlayers]==gHumanIconIndex[i++])
  156.                             {
  157.                                 gHumanIconIndex[gNumHumanPlayers]=24;
  158.                                 i=gNumHumanPlayers;
  159.                             }
  160.                         }
  161.                     }
  162.                 }
  163.                 else if (iconSelected>2)
  164.                     gHumanIconIndex[gNumHumanPlayers]=iconSelected-3;
  165.                 
  166.                 if (iconSelected!=2)
  167.                 {
  168.                     gHumanPlayerScore[gNumHumanPlayers]=0;
  169.                     gNumHumanPlayers++;
  170.                 }
  171.                 
  172.                 HideWindow(iconDlog);
  173.                 DisposeDialog(iconDlog);
  174.             }
  175.             else itemSelected=2;
  176.         }
  177.         done=((itemSelected!=1) || (gNumHumanPlayers==5));
  178.         play=(itemSelected!=3);
  179.     }
  180.     
  181.     return play;
  182. }
  183.  
  184. void OrderPlayers(void)
  185. {
  186.     Boolean        used[10];
  187.     int            PlayerNumber;
  188.     int            i;
  189.         
  190.     gNumPlayers=gNumComputerPlayers+gNumHumanPlayers;
  191.     for (i=0; i<gNumPlayers; i++)
  192.         used[i]=FALSE;
  193.     for (i=0; i<gNumPlayers; i++)
  194.     {
  195.         PlayerNumber=-1;
  196.         while (PlayerNumber<0)
  197.         {
  198.             while (PlayerNumber<0) PlayerNumber=Random()%gNumPlayers;
  199.             if (used[PlayerNumber])
  200.                 PlayerNumber=-1;
  201.         }
  202.         gPlayOrderIndex[i]=PlayerNumber;
  203.         used[PlayerNumber]=TRUE;
  204.     }
  205. }
  206.  
  207.